import Vue from 'vue'
import Vuex from 'vuex'
import * as actions from './actions'
import getters from './getters'
import permission from './modules/permission'
import user from './modules/user'

Vue.use(Vuex);

// 应用初始状态
const state = {
    count: 10,
    // 存储token
    Authorization: localStorage.getItem('Authorization') ? localStorage.getItem('Authorization') : ''
};

// 定义所需的 mutations
const mutations = {
    INCREMENT(state) {
        state.count++
    },
    DECREMENT(state) {
        state.count--
    },
    // 修改token，并将token存入localStorage
    changeLogin(state, user) {
        localStorage.setItem('Authorization', user.Authorization);
    }
};

// 创建 store 实例
export default new Vuex.Store({
    actions,
    getters,
    state,
    mutations,
    modules: {
        permission,
        user
    }
})